home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / iqb9107.zip / QTEST.BAS < prev    next >
BASIC Source File  |  1991-06-27  |  2KB  |  68 lines

  1. ' QTest.Bas
  2. ' QTest - Test the timer library. This program
  3. ' times how long it takes to obtain the current
  4. ' time with the two methods described in the
  5. ' article
  6.  
  7. DECLARE SUB PrintResults (A AS LONG, B AS LONG, S1 AS STRING, S2 AS STRING)
  8. DECLARE FUNCTION tStart& ()
  9. DECLARE FUNCTION tFormat$ (T1 AS LONG, T2 AS LONG)
  10. DECLARE FUNCTION tDiff! (StartTime AS LONG, EndTime AS LONG)
  11. DECLARE FUNCTION tGet& ()
  12. DECLARE SUB GetTime (H AS INTEGER, M AS INTEGER, S AS INTEGER, S100 AS INTEGER)
  13.  
  14. DIM SHARED EmptyLoopTime AS SINGLE
  15. DIM Q AS LONG
  16. DIM T1 AS LONG, T2 AS LONG, I AS LONG, J AS LONG
  17. DIM Hour AS INTEGER, Minute AS INTEGER
  18. DIM Second AS INTEGER, Sec100 AS INTEGER
  19.  
  20. T1 = tStart&
  21. FOR I = 1 TO 1000000
  22. NEXT I
  23. T2 = tGet&
  24. CALL PrintResults(T1, T2, "*** Empty Loop ***", "Loop.")
  25. EmptyLoopTime = tDiff(T1, T2)
  26.  
  27. T1 = tStart&
  28. FOR I = 1 TO 1000000
  29.    X = TIMER
  30. NEXT I
  31. T2 = tGet&
  32. CALL PrintResults(T1, T2, "*** QB TIMER ***", "function call.")
  33.  
  34. T1 = tStart&
  35. FOR I = 1 TO 1000000
  36.    CALL GetTime(Hour, Minute, Second, Sec100)
  37. NEXT I
  38. T2 = tGet&
  39. CALL PrintResults(T1, T2, "*** GetTime ***", "subprogram call.")
  40.  
  41. T1 = tStart&
  42. FOR I = 1 TO 1000000
  43.    Q = tGet&
  44. NEXT I
  45. T2 = tGet&
  46. CALL PrintResults(T1, T2, "*** tGet& ***", "function call.")
  47.  
  48. PRINT "Tests completed."
  49. END
  50.  
  51.  
  52. SUB PrintResults (A AS LONG, B AS LONG, S1 AS STRING, S2 AS STRING)
  53. ' PrintResults displays an accurate message only if you run the
  54. ' test loop 1,000,000 times
  55. DIM tInterval AS SINGLE
  56.   PRINT tFormat$(A, B);
  57.   PRINT " seconds for 1,000,000 invocations of "; S1
  58.   tInterval = tDiff!(A, B) - EmptyLoopTime
  59.   ' Adjust display for midnight crossover.
  60.   ' 60 * 60 * 24 is the number of seconds in a day/
  61.   IF tInterval < 0 THEN
  62.     tInterval = tInterval + (60! * 60! * 24!)
  63.   END IF
  64.   PRINT "This equals ";
  65.   PRINT USING "########.######"; tInterval;
  66.   PRINT " microseconds per "; S2
  67. END SUB
  68.